CC=gcc
DEBUG=-g
CFLAGS = -Wall -fpic -coverage -lm -std=c99

rngs.o: rngs.h rngs.c
	gcc -c rngs.c -g  $(CFLAGS)

dominion.o: dominion.h dominion.c rngs.o
	gcc -c dominion.c -g  $(CFLAGS)

playdom: dominion.o playdom.c
	gcc -o playdom playdom.c -g dominion.o rngs.o $(CFLAGS)

interface.o: interface.h interface.c
	gcc -c interface.c -g  $(CFLAGS)

player: player.c interface.o
	gcc -o player player.c -g  dominion.o rngs.o interface.o $(CFLAGS)

all: playdom player testDrawCard testBuyCard badTestDrawCard

unittestresults.out: unittest1.c unittest2.c unittest3.c unittest4.c cardtest1.c cardtest2.c cardtest3.c cardtest4.c unittestmain.c
	echo "Result for running unittest and cardtest tests:" > tests.out

	$(CC) -o cardtests unittestmain.c cardtest1.c cardtest2.c cardtest3.c cardtest4.c \
	unittest1.c unittest2.c unittest3.c unittest4.c \
	dominion.c rngs.c $(CFLAGS)		
	./cardtests >> unittestresults.out
	gcov -b dominion.c >> unittestresults.out

randomtestadventurer.out: randomtestadventurer.c rtestadventurermain.c dominion.c
	echo "Result for running randomtestadventurer test" > mytests.out
	$(CC) -o randomtestadventurer randomtestadventurer.c rtestadventurermain.c \
	dominion.c rngs.c $(CFLAGS)
	./randomtestadventurer >> randomtestadventurer.out
	gcov -b dominion.c >> randomtestadventurer.out

randomtestadventurer: randomtestadventurer.c rtestadventurermain.c dominion.c rngs.c
	$(CC) $(DEBUG) -o randomtestadventurer randomtestadventurer.c rtestadventurermain.c \
	dominion.c rngs.c $(CFLAGS)

randomtestcard.out: randomtestcard.c rtestsmithymain.c dominion.c rngs.c
	echo "Result of running randomtestcard test" > randomtestcard.out
	$(CC) $(DEBUG) -o randomtestcard randomtestcard.c rtestsmithymain.c \
	dominion.c rngs.c $(CFLAGS)	
	./randomtestcard >> randomtestcard.out
	gcov -b dominion.c >> randomtestcard.out

randomtestcard: randomtestcard.c rtestsmithymain.c dominion.c rngs.c
	$(CC) $(DEBUG) -o randomtestcard randomtestcard.c rtestsmithymain.c \
	dominion.c rngs.c $(CFLAGS)

mytests.out: mytestsmain.c \
	unittest1.c unittest2.c unittest3.c unittest4.c \
	cardtest1.c cardtest2.c cardtest3.c cardtest4.c \
	randomtestadventurer.c randomtestcard.c \
	dominion.c rngs.c
	echo "Result for all tests:"
	$(CC) -o mytests mytestsmain.c \
	cardtest1.c cardtest2.c cardtest3.c cardtest4.c \
	unittest1.c unittest2.c unittest3.c unittest4.c \
	randomtestadventurer.c randomtestcard.c \
	dominion.c rngs.c $(CFLAGS)
	./mytests >> mytests.out
	gcov -b dominion.c >> mytests.out


clean:
	rm -f *.o playdom.exe playdom test.exe test player player.exe testInit testInit.exe *.gcov *.gcda *.gcno *.so
	rm -f cardtests unittest1 unittest2 unittest3 unittest4
	rm -f cardtest1 cardtest2 cardtest3 cardtest4 cardtests
	rm -f randomtestadventurer
	rm -f unittestresults.out randomtestadventurer.out 
	rm -f mytests.out